package com.dingli.controller;

import com.dingli.framework.entity.Member;
import com.dingli.framework.entity.Role;
import com.dingli.framework.util.Encryption;
import com.dingli.framework.util.Response;
import com.dingli.service.IRoleService;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@CrossOrigin("*")
@RestController
@RequestMapping("/role")
@Api(tags = "管理员信息")
public class RoleController {

    @Autowired
    private IRoleService iRoleService;

    @GetMapping("/relist")
    @ApiOperation("管理员信息列表查询")
    public Response<PageInfo<Role>> relist(@ApiParam("查询条件")
                                             @RequestParam(required = false) String search,
                                           @ApiParam("页码") @RequestParam(required = false) Integer pageNum,
                                           @ApiParam("页面大小")
                                             @RequestParam(required = false) Integer pageSize) {
        return iRoleService.relist(search, pageNum, pageSize);
    }

    @PostMapping("/reinsert")
    @ApiOperation("管理员信息新增")
    public Object reinsert(@ApiParam("管理员信息") @RequestBody Role role) {
        role.setPassword(Encryption.md5(role.getPassword()));
        return iRoleService.reinsert(role);
    }

    @GetMapping("/MBselectById")
    @ApiOperation("管理员信息详情查看")
    public Response<Role> reselectById(@ApiParam("管理员ID") @RequestParam Long roleID) {
        return iRoleService.reselectById(roleID);
    }

    @PostMapping("/reupdateById")
    @ApiOperation("管理员信息修改")
    public Response<Object> reupdateById(@ApiParam("修改的管理员信息") @RequestBody Role role) {

        return iRoleService.reupdateById(role);
    }

    @GetMapping("/redeleteById")
    @ApiOperation("管理员用户信息删除")
    public Response<Object> redeleteById(@ApiParam("管理员ID") @RequestParam Long roleID) {
        return iRoleService.redeleteById(roleID);
    }
}
